package sg.edu.nus.iss.team8s.vmcs.control;
/**
 * 
 * @author Nie Xiaoyi
 *
 */
import java.awt.Button;
import java.awt.Label;
import java.util.Vector;

import sg.edu.nus.iss.team8s.vmcs.beans.Coin;
import sg.edu.nus.iss.team8s.vmcs.cache.CashStore;

public class CoinReceiver {

	private static CoinReceiver instance = null;
	/*private Button[] btnList;
	private Label totalMoneyValue;*/
	private int weight;
	private Vector<Coin> coins = new Vector<Coin>();
	private CoinReceiver(){
		
	}
	
	public static synchronized CoinReceiver getInstance(){
		if(instance == null){
			instance = new CoinReceiver();
		}
		return instance;
	}
	
	public int receiveCoin(){
		CashStore cash = CashStore.getInstance();
		Coin coin = cash.findCoin(weight);
		coins.add(coin);
		return coin.getValue();
		/*int totalValue = Integer.parseInt(this.totalMoneyValue.getText());
		totalValue += coin.getValue();
		totalMoneyValue.setText(String.valueOf(totalValue));
		
		setCoinInputBoxStatus(false);
		
		TransactionController tranController = TransactionController.getInstance();
		return tranController.processMoneyReceived(totalValue);*/
	}
	
	/*public void StartReceive(){
		setCoinInputBoxStatus(true);
	}*/
	
	/*public void setCoinInputBox(Button[] btnList){
		this.btnList = btnList;
	}
	
	public void setTotalMoneyValue(Label totalMoneyValue){
		this.totalMoneyValue = totalMoneyValue;
	}
	
	public int getTotalMoneyValue(){
		return Integer.parseInt(this.totalMoneyValue.getText());
	}*/
	
	/*public void continueReceive(){
		setCoinInputBoxStatus(true);
	}*/
	
	/*private void setCoinInputBoxStatus(boolean status){
		for(int i =0 ; i<btnList.length;i++){
			btnList[i].setEnabled(status);
		}
	}*/
	
	public void setCoinWeight(int weight){
		this.weight = weight;
	}
	
	/*public void setTotalMoneyValueText(String value){
		this.totalMoneyValue.setText(value);
	}*/
	
	public boolean storeCash(){
		boolean result = true;
		MachineryController machineryController = MachineryController.getInstance();
		for(int i=0;i<coins.size();i++){
			result &= machineryController.storeCoin(coins.get(i));
		}
		return result;
	}
	
	public void clearInputCoins(){
		coins.clear();
	}
}
